package netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;

/**
 * HttpServer
 *
 * @author liyixin
 * @date 2019/2/12
 */
public class HttpServer {

    public static void start() {
        EventLoopGroup bossGroup = new EpollEventLoopGroup();
        EventLoopGroup workerGroup = new EpollEventLoopGroup();
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap
                    .option(ChannelOption.SO_BACKLOG, 1024)
                    .group(bossGroup)
                    .channel(EpollServerSocketChannel.class)
                    .childHandler(new HttpServerInitializer());
            Channel ch = bootstrap.bind("172.31.15.54",11121).sync().channel();

            ch.closeFuture().sync();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            bossGroup.shutdownGracefully();
        }
    }
}
